package com.hwpt.controller.user;

import com.hwpt.dto.user.SendCodeDTO;
import com.hwpt.dto.user.VerifyCodeDTO;
import com.hwpt.result.Result;
import com.hwpt.service.VerificationCodeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/user/verifyCode")
@RequiredArgsConstructor
@Tag(name = "验证码接口")
@Slf4j
public class VerificationCodeController {

    private final VerificationCodeService verificationCodeService;

    @PostMapping("/send")
    @ApiOperation("发送验证码")
    public Result<Void> sendVerificationCode(@Valid @RequestBody SendCodeDTO sendCodeDTO) {
        log.info("发送验证码请求参数：{}", sendCodeDTO.toString());
        verificationCodeService.sendVerificationCode(sendCodeDTO);
        return Result.success();
    }

    @PostMapping("/verify")
    @ApiOperation("验证码校验")
    public Result<Void> verifyCode(@Valid @RequestBody VerifyCodeDTO verifyCodeDTO) {
        log.info("验证码开始校验，参数：{}", verifyCodeDTO.toString());
        verificationCodeService.verifyCode(verifyCodeDTO);
        return Result.success();
    }
}